package cn.stacey.blog.web.demo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.stacey.blog.domain.AjaxResponse;
import cn.stacey.blog.domain.Category;


//3.0以上的servlet版本可以用注解，就不用每次配置 

@WebServlet(urlPatterns="/table_data")
public class TableServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		System.out.println("servlet....");
		List<Category> list = new ArrayList<>();
		for(int i=0;i<10;i++) {
			Category c=new Category();
			c.setId(i);
			c.setPriority(i);
			c.setName("袁诗哈哈哈"+i);
			list.add(c);
			
		}
		AjaxResponse ajax = new AjaxResponse();
		ajax.setCode(0);
		ajax.setMsg("");
		ajax.setCount(100);
		ajax.setData(list);
		String string = JSON.toJSONString(ajax);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(string);

	}
}
